package com.lvyerose.hello.asymmetricgridviewtest.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.felipecsl.asymmetricgridview.library.Utils;
import com.felipecsl.asymmetricgridview.library.widget.AsymmetricGridView;
import com.felipecsl.asymmetricgridview.library.widget.AsymmetricGridViewAdapter;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lvyerose.hello.asymmetricgridviewtest.R;
import com.lvyerose.hello.asymmetricgridviewtest.adapter.MeListViewAdapter;
import com.lvyerose.hello.asymmetricgridviewtest.mode.CustomItem;

import java.util.ArrayList;
import java.util.List;

@ContentView(R.layout.activity_main)
public class MainActivity extends AppCompatActivity {
    @ViewInject(R.id.listview)
    private AsymmetricGridView listview;
    private MeListViewAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ViewUtils.inject(this);

        adapter = new MeListViewAdapter(this,getData());
        //设置每行显示的个数
        listview.setRequestedColumnCount(3);
        //设置横向最后间距(非每个item之间的) 此处不确定
        listview.setRequestedHorizontalSpacing(Utils.dpToPx(this, 1));
        //设置Adapter   其用法：使用第三方的AsymmetricAdapter 而AsymmetricAdapter实例化时需要参数为   上下文对象  AsymmetricGridView对象 以及传统的Adapter
        listview.setAdapter(new AsymmetricGridViewAdapter(this, listview, adapter));

    }

    /**
     * 获取listview中的每一项Item
     * @return 返回AsymmetricItem实例集合(AsymmetricItem为特许item)
     */
    private List getData(){
        ArrayList<CustomItem> list = new ArrayList<>();
        for(int i=0;i<50;i++){
            int colSpan = 1;
            int rowSpan = 1;
            if(i==0 || i==3 || i==6){
                colSpan = 1;
                rowSpan = 2;
            }
            CustomItem item = new CustomItem(colSpan, rowSpan,i);
            list.add(item);
        }
        return list;
    }

}
